<template>
  <div class="home layout" id="home">
    <div class="h" style="margin-top: 1rem">
      <div class="carousel wrapper">
        <el-carousel :interval="4000" height="300px">
          <el-carousel-item v-for="item in carouselList" :key="item">
            <div class="carousel-item relative">
              <img class="fit-cover" :src="item.cover" alt="" />
              <div class="title">{{ item.title }}</div>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
    </div>
    <div class="n">
      <div class="wrapper flex">
        <div class="n-content">
          <div class="navigator">
            <div class="menus flex flex-ac">
              <div class="menu-items">
                <div :class="tagId === 1 ? 'menu-item select' : 'menu-item'">
                  <router-link to="/home?tagid=1">游戏资讯</router-link>
                </div>
                <div :class="tagId === 2 ? 'menu-item select' : 'menu-item'">
                  <router-link to="/home?tagid=2">游戏圈子</router-link>
                </div>
                <div :class="tagId === 3 ? 'menu-item select' : 'menu-item'">
                  <router-link to="/home?tagid=3">赛事信息</router-link>
                </div>
              </div>
            </div>
          </div>
          <div class="wrap">
            <component :is="currentComponent"></component>
          </div>
        </div>
        <div class="n-aside">
          <Aside></Aside>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch, markRaw } from "vue";
import { useRoute } from "vue-router";
import Post from "@/components/Post.vue";
import Community from "@/components/Community.vue";
import Aside from "@/components/Aside.vue";

const tagId = ref<number>(1);

const componentMap = {
  1: markRaw(Post),
  2: markRaw(Community),
};

const currentComponent = ref(componentMap[1]);

const route = useRoute();

watch(
  () => route.query.tagid,
  (newVal) => {
    tagId.value = parseInt(newVal as string) || 1;
    currentComponent.value =
      componentMap[tagId.value as keyof typeof componentMap];
  },
  {
    immediate: true,
  }
);

const carouselList = [
  {
    cover: "https://img.hoshinagi.top/esport/picture.jpg",
    title: "BLAST盘点：哪位新后起之秀在2024下半年大放异彩？",
  },
  {
    cover: "https://img.hoshinagi.top/esport/picture.jpg",
    title: "BLAST盘点：哪位新后起之秀在2024下半年大放异彩？",
  },
  {
    cover: "https://img.hoshinagi.top/esport/picture.jpg",
    title: "BLAST盘点：哪位新后起之秀在2024下半年大放异彩？",
  },
];
</script>

<style scoped lang="scss">
.h {
  .h-inner {
    background-position: 50%;
    background-size: cover;
    transition: background-image 0.2s ease, background-size 1s ease;
    padding-top: 116px;
    position: relative;
  }
}

.carousel-item {
  width: 100%;
  height: 100%;

  .title {
    position: absolute;
    left: 40px;
    bottom: 15%;
    font-weight: bold;
    color: #fff;
    font-size: 25px;
    line-height: 25px;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  img {
    max-width: 100%;
    max-height: 100%;
  }
}

.n {
  .n-content {
    width: 65%;

    .wrap {
      margin-top: 1rem;
    }
  }

  .n-aside {
    width: 35%;
  }
}

.navigator {
  margin-top: 1rem;

  .menus {
    padding: 0.4rem 0.6rem;
    background: var(--xz-card-bg);
    transition: 0.3s;
    width: 100%;
    justify-content: space-between;
    border-radius: 12px;
    display: flex;
    white-space: nowrap;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    align-items: center;
    border: var(--style-border);

    .menu-items {
      white-space: nowrap;
      overflow-x: scroll;
      overflow-y: hidden;
      display: flex;
      border-radius: 8px;
      align-items: center;
      height: 30px;
      gap: 4px;

      .menu-item {
        &.select {
          a {
            background: var(--xz-theme);
            color: var(--xz-card-bg);
            border-radius: 8px;
          }
        }

        a {
          padding: 0.1rem 0.5rem;
          font-weight: 700;
          border-radius: 8px;
          display: flex;
          align-items: center;
          height: 30px;
          transition: all 0.3s ease-out 0s;
          overflow-wrap: break-word;
          -webkit-user-drag: none;
        }

        &:hover {
          a {
            background: var(--xz-lighttext);
            color: var(--xz-card-bg);
          }
        }
      }
    }
  }
}

.wrapper {
  width: 1283px !important;
  margin: 0 auto;
  position: relative;
}
</style>
